package pcloud.client.remoteservice;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import pcloud.client.util.FileResourceInfo;

public class WebDAVServiceTest
{
	FileService fileService; 
	@Before
	public void setUp() throws Exception
	{
		testCreateInstance();
	}

	@After
	public void tearDown() throws Exception
	{
	}

	private void testCreateInstance()
	{
//		fileService = WebDAVService.createInstance("http://demo.sabredav.org/public/pcloud","testuser","test");
//		fileService = WebDAVService.createInstance("http://demo.sabredav.org/public","testuser","test");
		fileService = WebDAVService.createInstance("http://localhost:8080/webdav","webdavuser","password");
	}

	@Test
	public void testCreateFolder()
	{

		try {
			fileService.createFolder("/WebDevServiceTest"+new Date().getTime());
//			fileService.createFolder("/pcloud");
		} catch (IOException e) {
			fail(e.getMessage());
		}
	}

//	@Test
//	public void testDeleteFolder()
//	{
//		try {
//			String path = "/WebDevServiceTest"+new Date().getTime();
//			fileService.createFolder(path);
//			fileService.deleteFolder(path);
//		} catch (IOException e) {
//			fail(e.getMessage());
//		}
//	}

	@Test
	public void testUploadFileFileResourceInfo()
	{
		FileResourceInfo file = new FileResourceInfo(new File("D:/pcloud/WatchTest/j.txt") );
		try {
			fileService.uploadFile(file);
		} catch (IOException e) {
			fail(e.getMessage());
		}
	}

	@Test
	public void testUploadFileStringInputStream()
	{
		File file = new File("D:/PCloud/WatchTest/j.txt");
		try {
			FileInputStream inputStream = new FileInputStream(file);
			fileService.uploadFile("/j.txt", inputStream);
		} catch (IOException e) {
			fail(e.getMessage());
		}
	}

	@Test
	public void testDownloadFileFileResourceInfo()
	{
		fail("Not yet implemented");
	}

	@Test
	public void testDownloadFileString()
	{
		fail("Not yet implemented");
	}

	@Test
	public void testList()
	{
		fail("Not yet implemented");
	}

	@Test
	public void testGetResource()
	{
		fail("Not yet implemented");
	}

}
